package com.fenghongzhang.kotlin5

import android.annotation.SuppressLint
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import com.fenghongzhang.kotlin5.day04.LogUtil
import com.fenghongzhang.kotlin5.day05.SPUitl
import com.orhanobut.logger.Logger
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    private lateinit var user:User
    private lateinit var student:Student


    var name:String by SPUitl.opertion("haha","xiaoming")

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        Logger.d(name)

        name = "daming"

        Logger.d(name)


//        Log.v("haha","v")
//        Log.d("haha","d")
//        Log.i("haha","i")
//        Log.w("haha","w")
//        Log.e("haha","e")

//        LogUtil.v("haha","v")
//        LogUtil.d("haha","d")
//        LogUtil.i("haha","i")
//        LogUtil.w("haha","w")
//        LogUtil.e("haha","e")

//        requestPermissions()
          Logger.d("hello")

//        val sharedPreferences = getSharedPreferences("user", Context.MODE_PRIVATE)
//        val edit = sharedPreferences.edit()
//        edit.putString("name","xiaoming")
//        edit.putString("name1","xiaoming1")
//        edit.putString("name2","xiaoming2")
//        edit.apply()
        getSharedPreferences("user",Context.MODE_PRIVATE).open {
            putString("name","xiaoming")
            putString("name1","xiaoming1")
            putString("name2","xiaoming2")
        }








        three.setOnClickListener{
            "ahh".toast(this)
        }



        user = User()
        user.name = "daming"
//
        student = Student()


        /**
         * 声明一个类
         * 创建一个对象
         * 声明一个接口
         * 声明一个可以继承的类
         * 让类继承类并实现接口
         * 延迟初始化lateinit
         *
         * kotlin的函数的扩展
         *
         * 数据类
         * 整个大虾串
         *
         *
         */


    }

    private fun testlist() {
        //        new String[]{"哈哈","banner","嘿嘿"}
        //        val a = listOf("哈哈","banner","嘿嘿")

        //        new ArrayList()'
        val mutableListOf = mutableListOf("哈哈", "嘿嘿", "呵呵")
        //        for (item in mutableListOf){
        //            Log.i("内容",item)
        //        }
        for (i in 0 until mutableListOf.size) {
            if (i == 1) {
                Log.i("内容", mutableListOf[i])
            }
        }
    }

    fun click(view: View) {
        when(view.id){
            R.id.one -> {
//                Toast.makeText(this,"one",Toast.LENGTH_SHORT).show()
                Log.i("log","user=${user.name}")
                Log.i("log","user=${student.name}")
                Log.i("log","user=${student.address}")

                student.eat()

            }
            R.id.two -> {
//                Toast.makeText(this,"two",Toast.LENGTH_SHORT).show()
//                  "two".toast(this)
                  1.toast(this)
            }
            else -> {
                Toast.makeText(this,"没有",Toast.LENGTH_SHORT).show()
            }
        }
    }
}
